package Views;

import Models.Round;
import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
/**
 * @author Thomas
 */
public class RoundTableModel extends DefaultTableModel
{
	private ArrayList<Round> rounds;

	public RoundTableModel()
	{
		this.rounds = new ArrayList<Round>();
	}

	public RoundTableModel(ArrayList<Round> rounds)
	{
		this.rounds = rounds;
	}

	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}

	public void setData(ArrayList<Round> rounds)
	{
		this.rounds = rounds;
		fireTableDataChanged();
	}

	public ArrayList<Round> getData()
	{
		return this.rounds;
	}

	@Override
	public int getColumnCount()
	{
		return 4;
	}

	@Override
	public int getRowCount()
	{
		if (this.rounds == null)
		{
			return 0;
		}
		else
		{
			return this.rounds.size();
		}
	}

	@Override
	public String getColumnName(int column)
	{
		String columnName = "";
		switch(column)
		{
			case 0:
				columnName = "RuteNr";
				break;
			case 1:
				columnName = "Kunde";
				break;
			case 2:
				columnName = "Adresse";
				break;
			case 3:
				columnName = "By";
				break;
		}
		return columnName;
	}

	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch(column)
		{
			case 0:
				value = this.rounds.get(row).getRoundNo();
				break;
			case 1:
				value = this.rounds.get(row).getLocation().getCustomer().getName();
				break;
			case 2:
				value = this.rounds.get(row).getLocation().getAddress();
				break;
			case 3:
				value = this.rounds.get(row).getLocation().getCity();
		}
		return value;
	}
}
